package main

import "fmt"

/*
运算符练习
 */
func main() {
	fmt.Println("------数学运算符")
	MathOperator()
	fmt.Println("------关系运算符")
	RelaOperator()
	fmt.Println("------逻辑运算符")
	LogicalOperator()
}

func MathOperator() {

	var a int = 21
	var b int = 10
	var c int

	fmt.Println("var a int = 21，b int = 10 ")
	c = a + b
	fmt.Println("c = a + b  ", c)
	c = a - b
	fmt.Println("c = a - b  ", c)
	c = a * b
	fmt.Println("c = a * b  ", c)
	c = a / b
	fmt.Println("c = a / b  ", c)
	c = a % b
	fmt.Println("c = a mod b  ", c)
	a++
	fmt.Println("a++  %d", a)
	a--
	fmt.Println("a--  %d", a)
}

func RelaOperator() {

	a := 21
	b := 10

	fmt.Println("a := 21，b := 10 ")
	if a == b {
		fmt.Println("a == b")
	} else {
		fmt.Println("a <> b")
	}
	if a < b {
		fmt.Println("a < b")
	} else {
		fmt.Println("a >= b")
	}

	if a > b {
		fmt.Println("a > b")
	} else {
		fmt.Println("a <= b")
	}

	a = 5
	b = 20

	fmt.Println("       a = 5，b = 20 ")
	if a <= b {
		fmt.Println("a <= b")
	}
	if b >= a {
		fmt.Println("b >= a")
	}
}

func LogicalOperator() {
	var a bool = true
	var b bool = false
	fmt.Println("********a = true   b = false")
	if a && b {
		fmt.Println(" a && b  true")
	}
	if a || b {
		fmt.Println(" a || b true")
	}

	a = false
	b = true

	fmt.Println("********a = false   b = true")
	if a && b {
		fmt.Println("a && b true")
	} else {
		fmt.Println("a && b false")
	}
	if !(a && b) {
		fmt.Println("!(a && b) true")
	}
}
